using System.Linq;
using System.Runtime.Serialization;
using System.Security.Principal;

namespace TheBoard.Models
{
    [DataContract]
    public class OpenIdIdentity : IIdentity, IUser
    {
        [DataMember]
        public string ClaimedIdentifier { get; set; }
        [DataMember]
        public OpenIdIdentityProperties Properties { get; set; }

        #region IIdentity Members

        public string Name
        {
            get { return Coalesce(Properties.FullName, Properties.NickName, Properties.Email) ?? ""; }
        }

        public string AuthenticationType
        {
            get { return "OpenId"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        #endregion

        private string Coalesce(params string[] strings)
        {
            return strings.FirstOrDefault(s => !string.IsNullOrEmpty(s));
        }


        public string Email
        {
            get { return Properties.Email; }
        }
    }
}